#pragma once

#include<iostream>
#include<vector>
#include<utility>
#include<string>
using namespace std;

enum state
{
	EXIST,
	EMPTY,
	DELETE
};

template<class K,class V>
struct HashData
{
	pair<K, V> _kv;
	state _state = EMPTY;
};

template<class K>
struct DefaultHash
{
	size_t operator()(const K& key)
	{
		return (size_t)key;
	}
};

template<>
struct DefaultHash<string>
{
	size_t operator()(const string& str)
	{
		size_t hash = 0;
		for (auto e : str)
		{
			hash *= 131;
			hash += e;
		}
		return hash;
	}
};

template<class K,class V,class hashfunc = DefaultHash<K>>

class Hash
{
public:
	Hash()
	{
		_table.resize(10);
	}

	bool insert(const pair<K, V>& kv)
	{
		hashfunc hf;
		size_t hashi = hf(kv.first) % _table.size();
		while (_table[hashi]._state == EXIST)
		{
			++hashi;
			hashi %= _table.size();
		}

		_table[hashi]._kv = kv;
		_table[hashi]._state = EXIST;
		_n++;
		return true;
	}
private:
	vector<HashData<K, V>> _table;
	size_t _n = 0;
};